package com.example.coroutines

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch


fun main(){
    // 创建一个协程作用域
    val  scope = CoroutineScope(Dispatchers.Default)
    //启动协程
    scope.launch {
        System.out.println("协程工作了"+Thread.currentThread().name)
    }
    //主线程结束，协程也会结束，主线程睡眠，保证协程工作
    Thread.sleep(2000)
    System.out.println(Thread.currentThread().name)
}